//; mapshader.fx written by Alex Anderson
//; @15.8.12

// ################
// ### Varibles ###
float4x4 World;
float4x4 View;
float4x4 Projection; 

float4 AmbientColor;
float AmbientLevel;
float4 Colour;
bool IsHovering = false;

Texture Texture;
sampler TextureSampler = sampler_state { texture = <Texture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};

// #######################
// ### Data Structures ###
struct VertexData {
	float4 Position : POSITION;
	float2 UV : TEXCOORD0;
	float3 Normal : TEXCOORD1;
	float3 Position3D : TEXCOORD2;
};

struct PixelData {
	float4 Color : COLOR0;
};

// ########################
// ### Shader Functions ###
VertexData MyVertexShader(float4 inPos : POSITION0, float3 inNormal: NORMAL0, float2 inTexCoords : TEXCOORD0)
{
	VertexData output = (VertexData)0;

	float4x4 vp = mul(View, Projection);
	float4x4 wvp = mul(World, vp);

	float4 position = mul(inPos, wvp).xyzw;	
	if(IsHovering)
		position.y += .5f;

	output.Position = position;
	output.UV = inTexCoords;
	output.Normal = normalize(mul(inNormal, (float3x3)World));
	output.Position3D = mul(inPos, World);

	return output;
}

PixelData CellPixelShader(VertexData inData)
{
	PixelData output = (PixelData)0;	
	
	output.Color = tex2D(TextureSampler, inData.UV);
	return output;
} 

PixelData FencePixelShader(VertexData inData)
{
	PixelData output = (PixelData)0;	
	
	output.Color = tex2D(TextureSampler, inData.UV) * Colour;
	return output;
}

// ##################
// ### Techniques ###
technique TextureShade
{
	pass Pass0
	{
		VertexShader = compile vs_2_0 MyVertexShader();
		PixelShader = compile ps_2_0 CellPixelShader();
	}
}
technique ColourShade
{
	pass Pass0
	{
		VertexShader = compile vs_2_0 MyVertexShader();
		PixelShader = compile ps_2_0 FencePixelShader();
	}
}